//
//  NSString+Utils64.m
//  fakeTouchDemo
//
//  Created by 洪冬介 on 2022/1/1.
//

#import "NSString+Utils64.h"

@implementation NSString (Utils64)

+ (NSString *)base64Encode:(NSString *)data{
    if (!data) {
        return nil;
    }
    NSData *sData = [data dataUsingEncoding:NSUTF8StringEncoding];
    NSData *base64Data = [sData base64EncodedDataWithOptions:0];
    NSString *baseString = [[NSString alloc]initWithData:base64Data encoding:NSUTF8StringEncoding];
    return baseString;
}
 
+ (NSString *)base64Dencode:(NSString *)data{
    if (!data) {
        return nil;
    }
    NSData *sData = [[NSData alloc]initWithBase64EncodedString:data options:NSDataBase64DecodingIgnoreUnknownCharacters];
    NSString *dataString = [[NSString alloc]initWithData:sData encoding:NSUTF8StringEncoding];
    return dataString;
}

/**
 * Base64解码
 * 返回 const char * 类型
 */
+(const char *)char_base64Dencode:(NSString *)data{
    NSString* str = [self base64Dencode:data];
    
    const char* strc = [str UTF8String];

    return strc;
}

@end
